package test.org.jrfe.t;

import java.io.IOException;

import org.jrfe.JRFE;
import org.jrfe.gfx.JRFERenderer;
import org.jrfe.gfx.Vertex;
import org.jrfe.gfx.VertexBatch;
import org.jrfe.gfx.g2d.shapes.Circle;
import org.jrfe.gfx.g2d.shapes.MappedTexture;
import org.jrfe.math.Vector2f;
import org.jrfe.res.JRFEResource;
import org.jrfe.res.Texture;
import org.jrfe.sys.JRFEContext;
import org.jrfe.sys.JRFEInput;
import org.jrfe.sys.JRFESettings;
import org.jrfe.sys.JRFESystem;
import org.jrfe.sys.input.KeyEvent;
import org.jrfe.sys.input.KeyListener;
import org.jrfe.sys.input.MouseEvent;
import org.jrfe.sys.input.MouseListener;

public class Grid implements JRFEContext,KeyListener,MouseListener{

	public static void main(String[] args) throws InterruptedException {
		
		JRFESettings set = new JRFESettings();
		set.fpslimit = 60;
		JRFESystem.createDisplay(set);
		JRFEResource.initilizeTextureManager();
		JRFESystem.setJRFEContext(new Grid());
		JRFESystem.start();
		JRFEResource.destroyTextureManager();
		JRFESystem.destroyDisplay();
	}

	int sec  = 0;
	int fps = 0;
	
	int fpsCount = 0;

	Circle c = new Circle(new Vector2f(),15,6);
	
	@Override
	public void mouseMoved(MouseEvent e) {
		c.getLocation().set(e.mouseX, e.mouseY);

	}
	@Override
	public void mousePressed(MouseEvent e) {

	}
	@Override
	public void mouseReleased(MouseEvent e) {

	}
	
	@Override
	public void keyPressed(KeyEvent evt) {

	}
	
	@Override
	public void keyReleased(KeyEvent evt) {

	}
	
	@Override
	public void keyTyped(KeyEvent evt) {
	
	}
	
	VertexBatch batch = new VertexBatch(4);
	
	@Override
	public boolean initialize() {
		JRFEInput.initilize();
		JRFEInput.setKeyListener(this);
		JRFEInput.setMouseListener(this);

		Vertex v = new Vertex();
		
		v.a = 1;
		v.r = 1;
		
		
	
		try {
			Texture t = JRFEResource.getTexManager().loadTexture("data/B.png");
			c.setMappedTexture(new MappedTexture(t,0,0,64,64));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return true;
	}
	@Override
	public boolean render() {
		JRFERenderer.beginScene();
		
		JRFERenderer.renderShape(c);
		
		JRFERenderer.endScene();
		// TODO Auto-generated method stub
		return true;
	}
	@Override
	public boolean update() {

		JRFEInput.capture();
		JRFEInput.process();
		
		fps++;
		
		sec += JRFESystem.getDeltaMS();
		
		if(sec >= 1000){
			fpsCount = fps;
			sec = 0;
			System.out.println(fpsCount);
			fps = 0;
		}
		
		if(JRFEInput.isKeyDownHW(JRFE.KeyCodes.KEY_ESCAPE)){
			return false;
		}
		
		return true;
	}
	@Override
	public void cleanup() {
		// TODO Auto-generated method stub
		
	}
}
